<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * This is the controller for login form
 *
 * @author		akjmgalp
 * @Revision	From SVN
 */

// ------------------------------------------------------------------------
class Login extends CI_Controller {

	public function index() {
		$data = array("main_view" => "login_form");
		$data['username'] = 'ibrahim';
		$this->load->view('templates/default/template', $data);
	}

	public function submit() {

		if ($this->_submit_validate() === FALSE) {
			$this->index();
			return;
		}

		redirect('/home');
	}

	private function _submit_validate() {

		$this->form_validation->set_rules('username', 'Kullanıcı Adı', 'trim|required|callback_authenticate');
		$this->form_validation->set_rules('password', 'Şifre', 'trim|required');
		$this->form_validation->set_message('authenticate','Bilgiler yanlış. Tekrar deneyiniz.');

		return $this->form_validation->run();
	}

	public function authenticate() {
		
		return Current_User::login($this->input->post('username'), $this->input->post('password'));
	}

}